<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable=no">
  <meta name="description" content="API docs for the parse method from the HttpDate class, for the Dart programming language.">
  <title>parse method - HttpDate class - dart:io library - Dart API</title>
  <!-- required because all the links are pseudo-absolute -->
  <base href="../..">

  <link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500,400i,400,300|Source+Sans+Pro:400,300,700" rel="stylesheet">
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  <link rel="stylesheet" href="static-assets/github.css">
  <link rel="stylesheet" href="static-assets/styles.css">
  <link rel="icon" href="static-assets/favicon.png">
  
</head>

<body>

<div id="overlay-under-drawer"></div>

<header id="title">
  <button id="sidenav-left-toggle" type="button">&nbsp;</button>
  <ol class="breadcrumbs gt-separated dark hidden-xs">
    <li><a href="index.html">manage_calendar_events</a></li>
    <li><a href="dart-io/dart-io-library.html">dart:io</a></li>
    <li><a href="dart-io/HttpDate-class.html">HttpDate</a></li>
    <li class="self-crumb">parse method</li>
  </ol>
  <div class="self-name">parse</div>
  <form class="search navbar-right" role="search">
    <input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
  </form>
</header>

<main>

  <div id="dartdoc-sidebar-left" class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left">
    <header id="header-search-sidebar" class="hidden-l">
      <form class="search-sidebar" role="search">
        <input type="text" id="search-sidebar" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
      </form>
    </header>
    
    <ol class="breadcrumbs gt-separated dark hidden-l" id="sidebar-nav">
      <li><a href="index.html">manage_calendar_events</a></li>
      <li><a href="dart-io/dart-io-library.html">dart:io</a></li>
      <li><a href="dart-io/HttpDate-class.html">HttpDate</a></li>
      <li class="self-crumb">parse method</li>
    </ol>
    
    <h5>HttpDate class</h5>
    <ol>
      <li class="section-title"><a href="dart-io/HttpDate-class.html#constructors">Constructors</a></li>
      <li><a href="dart-io/HttpDate/HttpDate.html">HttpDate</a></li>
    
      <li class="section-title inherited">
        <a href="dart-io/HttpDate-class.html#instance-properties">Properties</a>
      </li>
      <li class="inherited"><a href="dart-core/Object/hashCode.html">hashCode</a></li>
      <li class="inherited"><a href="dart-core/Object/runtimeType.html">runtimeType</a></li>
    
      <li class="section-title inherited"><a href="dart-io/HttpDate-class.html#instance-methods">Methods</a></li>
      <li class="inherited"><a href="dart-core/Object/noSuchMethod.html">noSuchMethod</a></li>
      <li class="inherited"><a href="dart-core/Object/toString.html">toString</a></li>
    
      <li class="section-title inherited"><a href="dart-io/HttpDate-class.html#operators">Operators</a></li>
      <li class="inherited"><a href="dart-core/Object/operator_equals.html">operator ==</a></li>
    
    
      <li class="section-title"><a href="dart-io/HttpDate-class.html#static-methods">Static methods</a></li>
      <li><a href="dart-io/HttpDate/format.html">format</a></li>
      <li><a href="dart-io/HttpDate/parse.html">parse</a></li>
    
    </ol>
  </div><!--/.sidebar-offcanvas-->

  <div id="dartdoc-main-content" class="col-xs-12 col-sm-9 col-md-8 main-content">
      <div><h1><span class="kind-method">parse</span> method</h1></div>

    <section class="multi-line-signature">
      <span class="returntype"><a href="dart-core/DateTime-class.html">DateTime</a></span>
            <span class="name ">parse</span>
(<wbr><span class="parameter" id="parse-param-date"><span class="type-annotation"><a href="dart-core/String-class.html">String</a></span> <span class="parameter-name">date</span></span>)
      
    </section>
    <section class="desc markdown">
      <p>Parse a date string in either of the formats
<a href="http://tools.ietf.org/html/rfc1123" title="RFC-1123">RFC-1123</a>,
<a href="http://tools.ietf.org/html/rfc850" title="RFC-850">RFC-850</a> or
ANSI C's asctime() format. These formats are listed here.</p>
<pre class="language-dart"><code>Thu, 1 Jan 1970 00:00:00 GMT
Thursday, 1-Jan-1970 00:00:00 GMT
Thu Jan  1 00:00:00 1970
</code></pre>
<p>For more information see <a href="http://tools.ietf.org/html/rfc2616#section-3.3.1" title="RFC-2616 section 3.1.1">RFC-2616 section
3.1.1</a>.</p>
    </section>
    
    <section class="summary source-code" id="source">
      <h2><span>Implementation</span></h2>
      <pre class="language-dart"><code class="language-dart">static DateTime parse(String date) {
  final int SP = 32;
  const List wkdays = const [&quot;Mon&quot;, &quot;Tue&quot;, &quot;Wed&quot;, &quot;Thu&quot;, &quot;Fri&quot;, &quot;Sat&quot;, &quot;Sun&quot;];
  const List weekdays = const [
    &quot;Monday&quot;,
    &quot;Tuesday&quot;,
    &quot;Wednesday&quot;,
    &quot;Thursday&quot;,
    &quot;Friday&quot;,
    &quot;Saturday&quot;,
    &quot;Sunday&quot;
  ];
  const List months = const [
    &quot;Jan&quot;,
    &quot;Feb&quot;,
    &quot;Mar&quot;,
    &quot;Apr&quot;,
    &quot;May&quot;,
    &quot;Jun&quot;,
    &quot;Jul&quot;,
    &quot;Aug&quot;,
    &quot;Sep&quot;,
    &quot;Oct&quot;,
    &quot;Nov&quot;,
    &quot;Dec&quot;
  ];
  const List wkdaysLowerCase = const [
    &quot;mon&quot;,
    &quot;tue&quot;,
    &quot;wed&quot;,
    &quot;thu&quot;,
    &quot;fri&quot;,
    &quot;sat&quot;,
    &quot;sun&quot;
  ];
  const List weekdaysLowerCase = const [
    &quot;monday&quot;,
    &quot;tuesday&quot;,
    &quot;wednesday&quot;,
    &quot;thursday&quot;,
    &quot;friday&quot;,
    &quot;saturday&quot;,
    &quot;sunday&quot;
  ];
  const List monthsLowerCase = const [
    &quot;jan&quot;,
    &quot;feb&quot;,
    &quot;mar&quot;,
    &quot;apr&quot;,
    &quot;may&quot;,
    &quot;jun&quot;,
    &quot;jul&quot;,
    &quot;aug&quot;,
    &quot;sep&quot;,
    &quot;oct&quot;,
    &quot;nov&quot;,
    &quot;dec&quot;
  ];

  final int formatRfc1123 = 0;
  final int formatRfc850 = 1;
  final int formatAsctime = 2;

  int index = 0;
  String tmp;
  int format;

  void expect(String s) {
    if (date.length - index &lt; s.length) {
      throw new HttpException(&quot;Invalid HTTP date $date&quot;);
    }
    String tmp = date.substring(index, index + s.length);
    if (tmp != s) {
      throw new HttpException(&quot;Invalid HTTP date $date&quot;);
    }
    index += s.length;
  }

  int expectWeekday() {
    int weekday;
    &#47;&#47; The formatting of the weekday signals the format of the date string.
    int pos = date.indexOf(&quot;,&quot;, index);
    if (pos == -1) {
      int pos = date.indexOf(&quot; &quot;, index);
      if (pos == -1) throw new HttpException(&quot;Invalid HTTP date $date&quot;);
      tmp = date.substring(index, pos);
      index = pos + 1;
      weekday = wkdays.indexOf(tmp);
      if (weekday != -1) {
        format = formatAsctime;
        return weekday;
      }
    } else {
      tmp = date.substring(index, pos);
      index = pos + 1;
      weekday = wkdays.indexOf(tmp);
      if (weekday != -1) {
        format = formatRfc1123;
        return weekday;
      }
      weekday = weekdays.indexOf(tmp);
      if (weekday != -1) {
        format = formatRfc850;
        return weekday;
      }
    }
    throw new HttpException(&quot;Invalid HTTP date $date&quot;);
  }

  int expectMonth(String separator) {
    int pos = date.indexOf(separator, index);
    if (pos - index != 3) throw new HttpException(&quot;Invalid HTTP date $date&quot;);
    tmp = date.substring(index, pos);
    index = pos + 1;
    int month = months.indexOf(tmp);
    if (month != -1) return month;
    throw new HttpException(&quot;Invalid HTTP date $date&quot;);
  }

  int expectNum(String separator) {
    int pos;
    if (separator.length &gt; 0) {
      pos = date.indexOf(separator, index);
    } else {
      pos = date.length;
    }
    String tmp = date.substring(index, pos);
    index = pos + separator.length;
    try {
      int value = int.parse(tmp);
      return value;
    } on FormatException catch (e) {
      throw new HttpException(&quot;Invalid HTTP date $date&quot;);
    }
  }

  void expectEnd() {
    if (index != date.length) {
      throw new HttpException(&quot;Invalid HTTP date $date&quot;);
    }
  }

  int weekday = expectWeekday();
  int day;
  int month;
  int year;
  int hours;
  int minutes;
  int seconds;
  if (format == formatAsctime) {
    month = expectMonth(&quot; &quot;);
    if (date.codeUnitAt(index) == SP) index++;
    day = expectNum(&quot; &quot;);
    hours = expectNum(&quot;:&quot;);
    minutes = expectNum(&quot;:&quot;);
    seconds = expectNum(&quot; &quot;);
    year = expectNum(&quot;&quot;);
  } else {
    expect(&quot; &quot;);
    day = expectNum(format == formatRfc1123 ? &quot; &quot; : &quot;-&quot;);
    month = expectMonth(format == formatRfc1123 ? &quot; &quot; : &quot;-&quot;);
    year = expectNum(&quot; &quot;);
    hours = expectNum(&quot;:&quot;);
    minutes = expectNum(&quot;:&quot;);
    seconds = expectNum(&quot; &quot;);
    expect(&quot;GMT&quot;);
  }
  expectEnd();
  return new DateTime.utc(year, month + 1, day, hours, minutes, seconds, 0);
}</code></pre>
    </section>

  </div> <!-- /.main-content -->

  <div id="dartdoc-sidebar-right" class="col-xs-6 col-sm-6 col-md-2 sidebar sidebar-offcanvas-right">
  </div><!--/.sidebar-offcanvas-->

</main>

<footer>
  <span class="no-break">
    manage_calendar_events 1.0.1
  </span>

  
</footer>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="static-assets/typeahead.bundle.min.js"></script>
<script src="static-assets/highlight.pack.js"></script>
<script src="static-assets/URI.js"></script>
<script src="static-assets/script.js"></script>


</body>

</html>
